from django.http import HttpResponse
import os
from django.shortcuts import render

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

def getUploadPage(request):
    return render(request, 'upload.html')

def upload(request):
    if request.method == "POST":
        myFile = request.FILES.get("photo", None)
        if not myFile:
            return HttpResponse("no files for upload!")
        destination = open(os.path.join(BASE_DIR,"upload", myFile.name), 'wb+')
        for chunk in myFile.chunks():
            destination.write(chunk)
        destination.close()
        return HttpResponse("upload over!")